#include "app/ApplicationConfig.h"
#include "app/Application.h"
#include "util/exceptions/Exception.h"
#include "util/logger/Logger.h"
#include "util/logger/LoggerManager.h"
#include "util/HashMap.h"

HashMap<std::string, std::string>* getParameters(int argumentsCount,
		char **userArgments);

int main(int argc, char **argv) {

	// se recopilan los parametros (de std input o de archivo).
	util::HashMap<std::string, std::string>* parameterMap = getParameters(argc - 1, argv);

	// se crea la aplicacion con los parametros leidos
	// TODO: Para mi se deberian pasar los parametros al crear la aplicacion.
	// y que ella se encargue de validarlos.
	//app::Application* app = new app::Application(parameterMap);
	app::Application* app = new app::Application();

	// se ejecuta la aplicacion
	try {
		app->run(parameterMap);
	} catch (util::Exception &e) {
		util::Logger* logger = util::LoggerManager::getInstance()->getLogger();
		logger->error(e.getMessage());
	}

	delete parameterMap;
	delete app;
	return 0;
}

HashMap<std::string, std::string>* getParameters(int argumentsCount, char **userArguments) {
	util::HashMap<std::string, std::string>* ret = new HashMap<std::string, std::string> ();
	int length = 5;
	std::string argumentsName[length];
	argumentsName[0] = "originName";
	argumentsName[1] = "originNumber";
	argumentsName[2] = "destinationName";
	argumentsName[3] = "destinationNumber";
	argumentsName[4] = "routeOptimize";
	for (int i = 0; i < argumentsCount; i++) {
		ret->put(new std::string(argumentsName[i]), new std::string(userArguments[i+1]));
	}
	return ret;
}
